import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/dialog_util.dart';
import 'package:leader_help/utils/util.dart';

import 'index.dart';

class DemandSubmitPage extends GetView<DemandSubmitController> {
  const DemandSubmitPage({Key? key}) : super(key: key);

  // 内容页
  Widget _buildView() {
    return Column(
      children: [
        Container(
          padding: EdgeInsets.all(10.r),
          decoration: const BoxDecoration(
            border: Border(bottom: BorderSide(color: Colors.white, width: 1)),
          ),
          child: Text(
            '任何您需要的且平台当前未满足的服务或情报均可通过此功能告知我们，平台将竭力满足您的需要。',
            style:
                pfMediumStyle(color: const Color(0xff67B029), fontSize: 14.sp),
          ),
        ),
        Expanded(
          child: Container(
            margin: EdgeInsets.all(10.r),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(5.r), color: Colors.white),
            child: TextField(
              controller: controller.state.textCtrl,
              expands: true,
              maxLines: null,
              minLines: null,
              style: pfMediumStyle(color: ColorsUtil.title, fontSize: 15.sp),
              decoration: InputDecoration(
                  hintText: '请语音或者手动录入您需要的情报或服务',
                  border: InputBorder.none,
                  contentPadding: EdgeInsets.all(10.r)),
            ),
          ),
        ),
        Row(
          children: [
            Expanded(
              child: InkWell(
                onTap: () {
                  showAlert(
                    title: '是否取消',
                    sureAction: () {
                      controller.mainCtrl.state.isShowAudioFloat = true;
                      Get.back();
                    },
                  );
                },
                child: Container(
                  height: 50.r,
                  decoration: BoxDecoration(
                      color: Colors.white,
                      border: Border.all(color: ColorsUtil.red)),
                  alignment: Alignment.center,
                  child: Text(
                    '取消',
                    style:
                        pfMediumStyle(color: ColorsUtil.title, fontSize: 16.sp),
                  ),
                ),
              ),
            ),
            Expanded(
              child: InkWell(
                onTap: () {},
                child: Container(
                  height: 50.r,
                  decoration: BoxDecoration(
                    color: ColorsUtil.red,
                  ),
                  alignment: Alignment.center,
                  child: Text(
                    '确定',
                    style: pfMediumStyle(color: Colors.white, fontSize: 16.sp),
                  ),
                ),
              ),
            ),
          ],
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () {
        controller.mainCtrl.state.isShowFloat = true;
        return Future.value(true);
      },
      child: GetBuilder<DemandSubmitController>(
        builder: (_) {
          return Scaffold(
            appBar: detailAppBar(
              context,
              title: '提需求',
              backTap: () {
                controller.mainCtrl.state.isShowFloat = true;
              },
            ),
            body: SafeArea(
              child: _buildView(),
            ),
            floatingActionButtonLocation: CustomFloatingActionButtonLocation(
                FloatingActionButtonLocation.centerTop, 0, 200.r),
            floatingActionButton: SizedBox(
              width: 80.r,
              height: 80.r,
              child: FloatingActionButton(
                onPressed: controller.actionDemand,
                backgroundColor: const Color(0x00000000),
                highlightElevation: 0,
                elevation: 0,
                child: Icon(
                  ProIconUtil.audio,
                  color: ColorsUtil.red,
                  size: 60.r,
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}

class CustomFloatingActionButtonLocation extends FloatingActionButtonLocation {
  FloatingActionButtonLocation location;
  double offsetX; // X方向的偏移量
  double offsetY; // Y方向的偏移量
  CustomFloatingActionButtonLocation(this.location, this.offsetX, this.offsetY);

  @override
  Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
    Offset offset = location.getOffset(scaffoldGeometry);
    return Offset(offset.dx + offsetX, offset.dy + offsetY);
  }
}
